package edu.uclmgmu.bacteriosec.aspects.com.mysql.jdbc.PreparedStatement.setString;

import com.mysql.jdbc.*;
import java.sql.*;

import edu.uclmgmu.bacteriosec.aspects.common.FilesStore;
import edu.uclmgmu.bacteriosec.aspects.common.Store;

privileged aspect PreparedStatementSetString_CountCalls {
	private String testMethod;
	
	before() : !within(PreparedStatementSetString_CountCalls) &&
						execution(public void *..test*(..)) {
		this.testMethod=thisJoinPointStaticPart.getSignature().toString();
	}

	after() : !within(PreparedStatementSetString_CountCalls) &&
						execution(public void *..test*(..)) {
		this.testMethod=null;
	}

	
	void around(java.sql.PreparedStatement caller, int col, String value) : target(caller) && args(col, value) && 
	call(* java.sql.PreparedStatement.setString(int, String))  &&
	!cflow(within(PreparedStatementSetString_CountCalls)) && !within(edu.uclmgmu.bacteriosec.aspects.common.FilesStore) {
		FilesStore.updateNumberOfCalls(thisJoinPointStaticPart.getSignature().toString(), this.testMethod);
		proceed(caller, col, value);
	}
	
/*
 * 
 	boolean around(com.mysql.jdbc.PreparedStatement caller) : target(caller) && 
	call(boolean com.mysql.jdbc.PreparedStatement.createStreamingResultSet()) {
		FilesStore.updateNumberOfCalls(thisJoinPointStaticPart.getSignature().toString(), this.testMethod);
		return proceed(caller);
	}	

	int around(com.mysql.jdbc.PreparedStatement caller, boolean a, boolean b) : target(caller) &&
	args(a, b) && 
	call(int com.mysql.jdbc.PreparedStatement.executeUpdate(boolean, boolean)) {
		FilesStore.updateNumberOfCalls(thisJoinPointStaticPart.getSignature().toString(), this.testMethod);
		return proceed(caller, a, b);
	}
	
	int around(com.mysql.jdbc.PreparedStatement caller, boolean a, boolean b) : target(caller) && args(a, b) && 
			call(* com.mysql.jdbc.PreparedStatement.executeUpdate(boolean, boolean)) {
		FilesStore.updateNumberOfCalls(thisJoinPointStaticPart.getSignature().toString(), this.testMethod);
		return proceed(caller, a, b);
	}
	
	void around(java.sql.PreparedStatement caller, int col, int value) : target(caller) && args(col, value) && 
	call(* java.sql.PreparedStatement.setInt(int, int)) {
		FilesStore.updateNumberOfCalls(thisJoinPointStaticPart.getSignature().toString(), this.testMethod);
		proceed(caller, col, value);
	}

 */
	
/*	Object around() : call(* *.*(..)) && 
			!cflow(within(PreparedStatement_CountCalls)) && !within(edu.uclmgmu.bacteriosec.aspects.common.Store) {
		Store.updateNumberOfCalls(thisJoinPointStaticPart.getSignature().toString());
		System.out.println("mysql\t" + thisJoinPointStaticPart.getSignature().toString() + "\t" +
				thisJoinPoint.getSignature().toString() + "\t" );
		return proceed();
	}
	*/
/*	Object around() : call(* com.mysql.jdbc.*.*(..))&& 
			!cflow(within(PreparedStatement_CountCalls)) && !within(edu.uclmgmu.bacteriosec.aspects.common.Store) 
			&& !within(junit.*) {
		Store.updateNumberOfCalls(thisJoinPointStaticPart.getSignature().toString());
		System.out.println("mysql\t" + thisJoinPointStaticPart.getSignature().toString() + "\t" +
				thisJoinPoint.getSignature().toString() + "\t" );
		return proceed();
	}*/
}
